/*
 * @Author: wwssaabb
 * @Date: 2021-09-04 15:31:02
 * @LastEditTime: 2021-10-29 17:26:21
 * @FilePath: \handwritten-code\demo\解析url参数.js
 */

function getQuery(url) {
  const reg = /([^?&=]+)=([^?&=]+)/g
  let res = {}
  url.replace(reg, function () {
    console.log(arguments)
    res[arguments[1]] = arguments[2]
  })
  return res
}

const url = 'https://www.bilibili.com/video/BV1Wp411d7Ur?from=search&seid=10983525170098859963'

console.log(get(url)) //{ from: 'search', seid: '10983525170098859963' }


function getQuery(url) {
  return url.match(/(?<=[?&])[^&]+/g).map(i => i.split('=')).reduce((p, c) => {
    p[c[0]] = c[1]
    return p
  }, {})
}